package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.EquipmentStatus;
import com.ruoyi.system.service.IEquipmentStatusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 设备状态Controller
 *
 * @author ruoyi
 * @date 2025-03-19
 */
@RestController
@RequestMapping("/system/status2")
public class EquipmentStatusController extends BaseController {
    @Autowired
    private IEquipmentStatusService equipmentStatusService;

    /**
     * 查询设备状态列表
     */
    //@PreAuthorize("@ss.hasPermi('system:status2:list')")
    @GetMapping("/list")
    public TableDataInfo list(EquipmentStatus equipmentStatus) {
        startPage();
        List<EquipmentStatus> list = equipmentStatusService.selectEquipmentStatusList(equipmentStatus);
        return getDataTable(list);
    }

    /**
     * 导出设备状态列表
     */
    //@PreAuthorize("@ss.hasPermi('system:status2:export')")
    //@Log(title= "设备状态", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EquipmentStatus equipmentStatus) {
        List<EquipmentStatus> list = equipmentStatusService.selectEquipmentStatusList(equipmentStatus);
        ExcelUtil<EquipmentStatus> util = new ExcelUtil<EquipmentStatus>(EquipmentStatus.class);
        util.exportExcel(response, list, "设备状态数据");
    }

    /**
     * 获取设备状态详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:status2:query')")
    @GetMapping(value = "/{equipmentId}")
    public AjaxResult getInfo(@PathVariable("equipmentId") String equipmentId) {
        return success(equipmentStatusService.selectEquipmentStatusByEquipmentId(equipmentId));
    }

    /**
     * 新增设备状态
     */
    //@PreAuthorize("@ss.hasPermi('system:status2:add')")
    //@Log(title= "设备状态", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EquipmentStatus equipmentStatus) {
        return toAjax(equipmentStatusService.insertEquipmentStatus(equipmentStatus));
    }

    /**
     * 修改设备状态
     */
    //@PreAuthorize("@ss.hasPermi('system:status2:edit')")
    //@Log(title= "设备状态", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EquipmentStatus equipmentStatus) {
        return toAjax(equipmentStatusService.updateEquipmentStatus(equipmentStatus));
    }

    /**
     * 删除设备状态
     */
    //@PreAuthorize("@ss.hasPermi('system:status2:remove')")
    //@Log(title= "设备状态", businessType = BusinessType.DELETE)
    @DeleteMapping("/{equipmentIds}")
    public AjaxResult remove(@PathVariable String[] equipmentIds) {
        return toAjax(equipmentStatusService.deleteEquipmentStatusByEquipmentIds(equipmentIds));
    }
}
